﻿using System;
using System.Data;
using System.Data.OleDb;

namespace EntityMetadata
{
    public class ExcelReader
    {
        private string _connectString;

        public ExcelReader(string xlsFilePath)
        {
            _connectString = 
                "Provider=Microsoft.ACE.OLEDB.12.0;" + 
                "Data Source=" + xlsFilePath + 
                ";Extended Properties='Excel 12.0;'";
        }

        public DataTable FillTable(DataSet ds, string tableName)
        {
            OleDbDataAdapter da = new OleDbDataAdapter(
                string.Format(
                    "SELECT * FROM [{0}$]",
                    tableName),
                _connectString);
            da.Fill( ds, tableName );
            return (ds.Tables[tableName]);
        }
    }
}
